package com.example.mumu.passwordbook.dao;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.graphics.drawable.Icon;

import com.example.mumu.passwordbook.domain.Account;
import com.example.mumu.passwordbook.domain.IconEnum;
import com.example.mumu.passwordbook.domain.TypeEnum;

import java.util.List;

public class AccountDBOpenHelper extends SQLiteOpenHelper {

    public AccountDBOpenHelper(Context context) {
        super(context, "account.db", null, 1);
    }

    @Override
    //数据库第一次创建时被调用
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("CREATE TABLE account(" +
                "id INTEGER PRIMARY KEY AUTOINCREMENT," +
                "name VARCHAR(100)," +
                "icon VARCHAR(20)," +
                "type VARCHAR(20)," +
                "username VARCHAR(100)," +
                "password VARCHAR(100)," +
                "remark VARCHAR(300))");


        for (IconEnum icon : IconEnum.values()) {
            db.execSQL("insert into account(name,icon,type) values(?,?,?)", new Object[]{icon.getName(), icon.toString(), icon.getType().toString()});
        }
    }

    //软件版本号发生改变时调用
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
//        db.execSQL("ALTER TABLE person ADD phone VARCHAR(12) NULL");
    }
}
